home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / disk utilities / backup / backup_restore / backup_src_v3.20.lha / cdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-28  |  3.2 KB  |  109 lines

  1. /*********************************************************************/
  2. /*                                                                   */
  3. /*  Program name:  cdio                                              */
  4. /*                                                                   */
  5. /*  Purpose:  To provide standard console device interface routines  */
  6. /*            such as Open, GetChar, PutChar, etc.                   */
  7. /*                                                                   */
  8. /*  Arguments:  (window)    - The window to associate the console    */
  9. /*                            device with. Used in CDOpen.           */
  10. /*              (character) - The char to output. Used in CDPutChar  */
  11. /*              (string)    - The string to output. Used in CDPutStr */
  12. /*                                                                   */
  13. /*  Programer:  Stan Shepard                                         */
  14. /*                                                                   */
  15. /*  Date Released:  27 Jan 1996 19:15:00                             */
  16. /*                                                                   */
  17. /*********************************************************************/
  18.  
  19. extern int CDOpen(struct Window *);
  20. extern void CDClose(void);
  21. extern void CDPutChar(char);
  22. extern void CDPutStr(const char *);
  23. extern void CDPutStrLength(const char *string, size_t Length);
  24.  
  25.  
  26. struct IOStdReq consoleIO;
  27. struct MsgPort consoleMsgPort;
  28. BOOL portda = FALSE, ConsoleOpen = FALSE;
  29.  
  30.  
  31. int CDOpen(struct Window *window)
  32. {
  33.     int error;
  34.                 
  35.     assert(!ConsoleOpen);
  36.  
  37.     /* Open the console device */
  38.     consoleIO.io_Data = (APTR) window;
  39.     consoleIO.io_Length = sizeof(*window);
  40.     if ((error = OpenDevice((UBYTE *)"console.device", 0, (struct IORequest *) &consoleIO, 0)) != 0)
  41.         {
  42.         printf("CDInit OpenDevice error: %d.\n", error);
  43.         return(error);
  44.         }
  45.     ConsoleOpen = TRUE;
  46.  
  47.     /* Set up the message port in the I/O request */
  48.     consoleMsgPort.mp_Node.ln_Type = NT_MSGPORT;
  49.     consoleMsgPort.mp_Flags = 0;
  50.     consoleMsgPort.mp_SigBit = AllocSignal(-1);
  51.     consoleMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
  52.     portda = TRUE;
  53.     consoleIO.io_Message.mn_ReplyPort = &consoleMsgPort;
  54.  
  55.     return(0);
  56. }
  57.  
  58.  
  59. void CDClose()
  60. {
  61.     if (portda)
  62.         {
  63.         FreeSignal(consoleMsgPort.mp_SigBit);
  64.         portda = FALSE;
  65.         }
  66.     if (ConsoleOpen)
  67.         {
  68.             CloseDevice((struct IORequest *) &consoleIO);
  69.         ConsoleOpen = FALSE;
  70.         }
  71. }
  72.  
  73.  
  74. void CDPutChar(char character)
  75. {
  76.     assert(ConsoleOpen);
  77.  
  78.         consoleIO.io_Command = CMD_WRITE;
  79.         consoleIO.io_Data = (APTR) &character;
  80.         consoleIO.io_Length = 1;
  81.         DoIO((struct IORequest *) &consoleIO);
  82. }
  83.  
  84.  
  85. /*  NULL terminated string to output  */
  86. void CDPutStr(const char *string)
  87. {
  88.     assert(ConsoleOpen);
  89.  
  90.         consoleIO.io_Command = CMD_WRITE;
  91.         consoleIO.io_Data = (APTR) string;
  92.         consoleIO.io_Length = -1;
  93.         DoIO((struct IORequest *) &consoleIO);
  94. }
  95.  
  96.  
  97. /*  NULL terminated string to output  */
  98. void CDPutStrLength(const char *string, size_t Length)
  99. {
  100.     assert(ConsoleOpen);
  101.  
  102.         consoleIO.io_Command = CMD_WRITE;
  103.         consoleIO.io_Data = (APTR) string;
  104.         consoleIO.io_Length = Length;
  105.         DoIO((struct IORequest *) &consoleIO);
  106. }
  107.  
  108.  
  109.